package yunjiao.javatutorials.mq.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import yunjiao.javatutorials.mq.component.BusinessDataSyncService;

import java.util.Objects;

/**
 * 测试接口：触发MQ消息发送
 *
 * @author yangyunjiao
 */
@RestController
@RequestMapping("/mq/sender")
@RequiredArgsConstructor
public class SenderController {
    private final BusinessDataSyncService businessDataSyncService;

    @GetMapping("/user")
    public ResponseEntity<String> syncUser() {
        businessDataSyncService.syncSingleUser();
        return ResponseEntity.ok("用户同步请求已触发");
    }

    // 测试批量订单同步
    @GetMapping("/order/batch")
    public ResponseEntity<String> syncBatchOrder(@RequestParam(name = "size", required = false) Integer size) {
        businessDataSyncService.syncBatchOrder(Objects.requireNonNullElse(size, 3));
        return ResponseEntity.ok("订单批量同步请求已触发：size=" + size);
    }
}
